// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/iot/api/IotDeviceTypeApiApi'

import AddClass from '@api/iot/model/DeviceTypeOperateReq'
import DelClass from '@api/iot/model/DeviceTypeBaseReq'
import BaseClass from '@api/iot/model/DeviceTypeDto'

const EditClass = AddClass
const DownClass = DelClass

const CLIENT = CORE.grpcCLIENT(Client)
const BASE = [BaseClass, 'content']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 增 —————————————————————————————— //

  async add(one, TIP = '新增') {
    const DTO = CORE.grpcDTO(AddClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'insertDeviceType', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 改 —————————————————————————————— //

  async edit(one, TIP = '修改') {
    const DTO = CORE.grpcDTO(EditClass, one, BASE)
    await CORE.grpc(TIP, CLIENT, 'updateDeviceType', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 删 —————————————————————————————— //

  async del({ id }, TIP = '删除') {
    const DTO = CORE.grpcDTO(DelClass, { ids: [id] })
    await CORE.grpc(TIP, CLIENT, 'deleteDeviceType', DTO)
    return CORE.grpcOK(TIP)
  },

  // —————————————————————————————— 下载 —————————————————————————————— //

  async download(downParam, TIP = '下载') {
    const DTO = CORE.grpcDTO(DownClass, downParam)
    const resp = await CORE.grpc(TIP, CLIENT, 'exportDeviceTypeJson', DTO)
    return resp
  },
  dealDownload(resp) {
    //
  },
}
